package baiwa.rta.service.Impl;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import baiwa.rta.dao.ComboboxDao;
import baiwa.rta.model.Role;
import baiwa.rta.model.TowerModel;
import baiwa.rta.service.ComboboxService;
import baiwa.rta.view.SelectBoxView;

@Service("ComboboxService")
@Transactional(readOnly = true)
public class ComboboxServiceImpl implements ComboboxService {
	
	private static int FLOOR_NO_START = 8;
	private static int FLOOR_NO_END = 50;

	@Autowired
	ComboboxDao dao;

	@Override
	public List<SelectBoxView> getTower() {
		List<SelectBoxView> v = new ArrayList<SelectBoxView>();
		v.add(new SelectBoxView("A" , "Tower A"));
		v.add(new SelectBoxView("B" , "Tower B"));
		v.add(new SelectBoxView("C" , "Tower C"));
		v.add(new SelectBoxView("D" , "Tower D"));
		return v;
	}

	@Override
	public List<SelectBoxView> getFloor(TowerModel model) {
		List<SelectBoxView> v = new ArrayList<SelectBoxView>();
//		List<TowerModel> list = dao.findTower(model);
//		for (TowerModel m : list) {
//			v.add(new SelectBoxView(m.getFloor() , m.getFloor()));
//		}
		for (int i = FLOOR_NO_START ; i <= FLOOR_NO_END ; i++) {
			v.add(new SelectBoxView(  i+"" , i+"" ));
		}
		return v;
	}

	@Override
	public List<SelectBoxView> getUnit(TowerModel model) {
		List<SelectBoxView> v = new ArrayList<SelectBoxView>();
		List<TowerModel> list = dao.findTower(model);
		for (TowerModel m : list) {
			v.add(new SelectBoxView(m.getUnitNo() , m.getUnitNo()));
		}
		return v;
	}

	@Override
	public List<SelectBoxView> getAddress(TowerModel model) {
		List<SelectBoxView> v = new ArrayList<SelectBoxView>();
		List<TowerModel> list = dao.findTower(model);
		for (TowerModel m : list) {
			v.add(new SelectBoxView(m.getAddress() , m.getAddress()));
		}
		return v;
	}

	@Override
	public List<TowerModel> getTowerModelByCriteria(TowerModel tower) {
		return dao.findTower(tower);
	}

	@Override
	public List<SelectBoxView> getActiveRole() {
		List<SelectBoxView> v = new ArrayList<SelectBoxView>();
		List<Role> list = dao.findActiveRole();
		for (Role r : list) {
			v.add(new SelectBoxView(r.getRoleId()+"" , r.getRoleName()));
		}
		return v;
	}



}
